package com.sparkflow.mysqlbinlog.clickhousesync;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;
import java.net.InetAddress;

/**
 * MySQL Binlog到ClickHouse同步应用主启动类
 * 负责启动和初始化整个同步服务
 *
 * @author Mr_xiaoZH
 * @date 2025-07-23
 */
@Slf4j
@SpringBootApplication
public class BinlogSyncApplication implements ApplicationRunner {

    @Resource
    private Environment environment;

    public static void main(String[] args) {
        SpringApplication.run(BinlogSyncApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        String serverPort = environment.getProperty("server.port", "8080");
        String hostAddress = InetAddress.getLocalHost().getHostAddress();

        log.info("==========================================================");
        log.info("MySQL Binlog to ClickHouse Sync Application Started Successfully!");
        log.info("Application Name: {}", environment.getProperty("spring.application.name"));
        log.info("Server Port: {}", serverPort);
        log.info("Local Access: http://localhost:{}", serverPort);
        log.info("External Access: http://{}:{}", hostAddress, serverPort);
        log.info("MySQL Binlog Host: {}", environment.getProperty("mysql.binlog.host"));
        log.info("ClickHouse URL: {}", environment.getProperty("clickhouse.url"));
        log.info("==========================================================");
    }
}
